package com.whalehearing.tingyou.web.controller.hearing;

import com.whalehearing.tingyou.common.annotation.DataSource;
import com.whalehearing.tingyou.common.annotation.Log;
import com.whalehearing.tingyou.common.core.controller.BaseController;
import com.whalehearing.tingyou.common.core.domain.AjaxResult;
import com.whalehearing.tingyou.common.core.page.TableDataInfo;
import com.whalehearing.tingyou.common.enums.BusinessType;
import com.whalehearing.tingyou.common.enums.DataSourceType;
import com.whalehearing.tingyou.common.utils.poi.ExcelUtil;
import com.whalehearing.tingyou.domain.HearingAudiogram;
import com.whalehearing.tingyou.service.IHearingAudiogramService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 听力档案Controller
 *
 * @author zengjun-qxm
 * @date 2024-09-13
 */
@Api(tags = "听力档案管理")
@RestController
@RequestMapping("system/hearing/audiogram")
public class HearingAudiogramController extends BaseController {
    @Autowired
    private IHearingAudiogramService hearingAudiogramService;

    /**
     * 查询听力档案列表
     */
    @ApiOperation("查询听力档案列表")
    @PreAuthorize("@ss.hasPermi('hearing:audiogram:list')")
    @GetMapping("/list")
    public TableDataInfo list(HearingAudiogram hearingAudiogram) {
        startPage();
        List<HearingAudiogram> list = hearingAudiogramService.selectHearingAudiogramList(hearingAudiogram);
        return getDataTable(list);
    }

    /**
     * 导出听力档案列表
     */
    @ApiOperation("导出听力档案列表")
    @PreAuthorize("@ss.hasPermi('hearing:audiogram:export')")
    @Log(title = "听力档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HearingAudiogram hearingAudiogram) {
        List<HearingAudiogram> list = hearingAudiogramService.selectHearingAudiogramList(hearingAudiogram);
        ExcelUtil<HearingAudiogram> util = new ExcelUtil<HearingAudiogram>(HearingAudiogram.class);
        util.exportExcel(response, list, "听力档案数据");
    }

    /**
     * 获取听力档案详细信息
     */
    @ApiOperation("获取听力档案详细信息")
    @PreAuthorize("@ss.hasPermi('hearing:audiogram:query')")
    @GetMapping(value = "/{audiogramId}")
    public AjaxResult getInfo(@PathVariable("audiogramId") Long audiogramId) {
        return success(hearingAudiogramService.getById(audiogramId));
    }

    /**
     * 新增听力档案
     */
    @ApiOperation("新增听力档案")
    @PreAuthorize("@ss.hasPermi('hearing:audiogram:add')")
    @Log(title = "听力档案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HearingAudiogram hearingAudiogram) {
        return toAjax(hearingAudiogramService.save(hearingAudiogram));
    }

    /**
     * 修改听力档案
     */
    @ApiOperation("修改听力档案")
    @PreAuthorize("@ss.hasPermi('hearing:audiogram:edit')")
    @Log(title = "听力档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HearingAudiogram hearingAudiogram) {
        return toAjax(hearingAudiogramService.updateById(hearingAudiogram));
    }

    /**
     * 删除听力档案
     */
    @ApiOperation("删除听力档案")
    @PreAuthorize("@ss.hasPermi('hearing:audiogram:remove')")
    @Log(title = "听力档案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{audiogramIds}")
    public AjaxResult remove(@PathVariable Long[] audiogramIds) {
        return toAjax(hearingAudiogramService.removeByIds(Arrays.asList(audiogramIds)));
    }
}
